﻿using System;
using System.Net;
using System.Net.Sockets;

namespace GW2SE.Base
{

    #region Delegtes
    public delegate void NetworkEventHandler(IPAddress Address, Int32 Port);
    #endregion

    public class Server
    {

        #region Variables
        TcpListener sListener;
        TcpClient sClient;
        bool sRunning;
        #endregion

        #region Events
        #endregion

        /// <summary>
        /// Initializes a new instance of the Server object
        /// </summary>
        public Server()
        {

        }

        public void Start(IPAddress Address, Int32 Port)
        {
            sListener = new TcpListener(Address, Port);
            sListener.Start();
            sRunning = true;
        }

        public void Stop()
        {
            sListener.Stop();
            sRunning = false;
        }

        public TcpClient AcceptClient()
        {
            return sListener.AcceptTcpClient();
        }

        #region Properties
        public bool Running { get { return sRunning; } }
        public bool Pending { get { if (Running) return sListener.Pending(); else return false; } }
        #endregion
    }
}
